package com.zx._03_并发.chapter_05_concurrent;

import java.util.HashSet;
import java.util.concurrent.CopyOnWriteArraySet;
import lombok.extern.slf4j.Slf4j;
import org.springframework.util.StopWatch;

/**
 * CopyOnWriteArraySet
 */
@Slf4j
public class Demo_02 {

    public static void main(String[] args) {
        StopWatch sw = new StopWatch();//计时器
        int total = 5000;
        CopyOnWriteArraySet<String> a = new CopyOnWriteArraySet<>();
        HashSet<String> b = new HashSet<>();

        sw.start("HashSet");
        for (int i = 0; i < total; i++) {
            b.add(String.valueOf(i));
        }
        sw.stop();

        sw.start("CopyOnWriteArraySet");
        for (int i = 0; i < total; i++) {
            a.add(String.valueOf(i));
        }
        sw.stop();

        log.info(sw.prettyPrint());
    }
}
